/*
 * argument.h
 *
 *  Created on: Jun 3, 2011
 *      Author: tqlong
 */

#ifndef ARGUMENT_H_
#define ARGUMENT_H_

/** Argument of a function is a list of variable (indices) in a universe */
class Argument : protected std::vector<int>
{
  typedef std::vector<int> __Base;
public:
  Argument()
  {
  }

  /** add a new variable to the argument */
  Argument&
  addVariable(int varIdx)
  {
    push_back(varIdx);
    return *this;
  }

  int
  n_var() const
  {
    return size();
  }

  /** get variable index */
  int
  varIdx(int var) const
  {
    return this->at(var);
  }

  /** fixed an argument by remove constant arguments in the universe */
  Argument
  fixed(const Universe& u) const
  {
    Argument arg;
    for (int i = 0; i < n_var(); i++)
      if (u.value(varIdx(i)) < 0)
      {
        arg.addVariable(varIdx(i));
      }
    return arg;
  }
};

template <typename OS>
OS& operator<<(OS& os, const Argument& a)
{
  if (a.n_var() == 0) return os;
  os << a.varIdx(0);
  for (int i = 1; i < a.n_var(); i++)
    os << "," << a.varIdx(i);
  return os;
}

#endif /* ARGUMENT_H_ */
